﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using VideoSystem;

namespace VideoSystem
{
    public class UserDb : IUserDb
    {
        private string tableAppUsers = "AppUsers";

        // This method returns a list with all Users in the database
        public List<User> GetAllAppUsers()
        {
            string sql = "SELECT * FROM " + tableAppUsers;
            SqlCommand cmd = DBConnection.GetDbCommand(sql);
            SqlDataReader reader = cmd.ExecuteReader();

            List<User> users = new List<User>();

            while (reader.Read())
            {
                string appUserId = reader["RegId"].ToString();

                users.Add(new User(appUserId));
            }
            reader.Close();
            DBConnection.CloseConnection();

            if (users.Count < 1)
            {
                return null;
            }

            return users;
        }
    }
}
